#!/bin/sh
#
# mmm_agent    This shell script takes care of starting and stopping
#              the mmm monitoring daemon.
#
# chkconfig: - 64 36
# description:  MMM Monitor.
# processname: mmmd_mon
# config: /usr/local/mmm/etc/mmm_mont.conf
# pidfile: /usr/local/mmm/var/mmmd_mon.pid

# Cluster name (it can be empty for default cases)
CLUSTER=''

# Paths
MMMD_BASE="/usr/local/mmm"

#-----------------------------------------------------------------------
if [ "$CLUSTER" != "" ]; then
    MMMD_BIN="${MMMD_BASE}/sbin/mmmd_mon @$CLUSTER"
    MMMD_PIDFILE="${MMMD_BASE}/var/mmmd-$CLUSTER.pid"
else 
    MMMD_BIN="${MMMD_BASE}/sbin/mmmd_mon"
    MMMD_PIDFILE="${MMMD_BASE}/var/mmmd.pid"
fi

echo "Daemon bin: '$MMMD_BIN'"
echo "Daemon pid: '$MMMD_PIDFILE'"

#-----------------------------------------------------------------------
# See how we were called.
case "$1" in
  start)
        # Start daemon.
        echo -n "Starting MMM Monitor daemon: "
        $MMMD_BIN
        RETVAL=$?
        echo "Ok"
        ;;

  stop)
        # Stop daemon.
        echo -n "Shutting down MMM Monitor daemon: "
        kill `cat $MMMD_PIDFILE`
        RETVAL=$?
        echo "Ok"
        ;;

  restart|reload)
        $0 stop
        echo -n "Waiting 10 sec before restart...";
        sleep 10
        echo "Ok"
        $0 start
        ;;

  *)
        echo "Usage: $0 {start|stop|restart}"
        RETVAL=1
        ;;
esac

exit $RETVAL
